<?php

declare(strict_types=1);

namespace App\Model\HmCommodityModel;
use App\Model\BaseModel\BaseHmCommodityModel;
use Hyperf\DbConnection\Db;
class HmSupplierCommodity extends BaseHmCommodityModel
{
    public $table = 'hm_suppliercommodity_s2b';
    
    /**
     * 获取供应商商品总数
     * @param unknown $supplierID
     * @param int $isConvertOss
     */
    public function getGoodsTotalCount($supplierID,int $isConvertOss = 0)
    {
        return $this->where('SupplierCompanyID',$supplierID)->where('isConvertOss',$isConvertOss)->count();
    }
    
    /**
     * 通过供应商id查询出商品信息
     * @param $supplierCompanyID
     * @param string $ID
     * @param int $limit
     * @param string $maxSupplierCommodityId
     * @param int $isConvertOss
     */
    public function getCommodityListBySupplierCompanyID($supplierCompanyID,$lastPageId = 0, int $limit =100,$maxSupplierCommodityId,int $isConvertOss = 0)
    {
        $where = [
            //['ID','=','10951'],
            ['SupplierCompanyID','=',$supplierCompanyID],
            ['ID','>',(string)$lastPageId],
            ['IsNeedDown','=',0],
            //['ID','<=',(string)$maxSupplierCommodityId],
            ['isConvertOss','=',$isConvertOss],
        ];
        
        return $this
        ->where($where)
        ->limit($limit)
        ->orderBy('ID','ASC')
        ->get()
        ->toArray();
    }
    
    /**
     * 获取最大一条商品信息
     * @param string $supplierCompanyID
     * @param int $isConvertOss
     */
    public function getMaxHmSupplierCommodityBySupplierCompanyID(string $supplierCompanyID,int $isConvertOss = 0 )
    {
        $where = [
            ['SupplierCompanyID','=',$supplierCompanyID],
            ['isConvertOss','=',$isConvertOss],
        ];
        $CommodityList = $this
        ->select([
            Db::raw('max(ID) as max_id')
        ])
        ->where($where)
        ->first()
        ->toArray();
        return $CommodityList;
    }

}
